//引入模块
const Koa = require('koa'),
    render = require('koa-art-template'),
    router = require('koa-router')(),
    path = require('path'),
    static = require('koa-static')
    bodyParser = require('koa-bodyparser');

//创建koa实例
const app = new Koa();

//配置模板引擎
render(app, {
    root: path.join(__dirname, 'views'),
    extname: '.html',
    debug: process.env.NODE_ENV !== 'production'
});

//配置静态资源
app.use(static('static'));

//配置bodyparser
app.use(bodyParser());


//配置路由
router.get('/', async (ctx) => {

    //输出末班内容

    //给模板传json数据
    let myname = 'jack';
    let myage = 20;

    let list = { name: myname, age: myage }
    await ctx.render('home', {
        datas: list
    });
})

router.get('/reg',async(ctx)=>{
await ctx.render('reg');
})

router.post('/regdo',async(ctx)=>{
    let data = ctx.request.body;
    console.log(data);
    ctx.body = '接受post表单数据';
})








//开启路由
app
    .use(router.routes())
    .use(router.allowedMethods());

//开启服务器监听
app.listen(3003);